package com.panasonic.cn.cmsc;

import java.math.BigDecimal;
import java.util.Hashtable;

import com.fujitsu.fks.jaaf.core.FrameworkCommon;
import com.fujitsu.fks.jaaf.core.FrameworkDbCommon;
import com.fujitsu.fks.jaaf.core.SelectResultRset;

public class SQLMScmmd10{
	private Hashtable paramsString     = new Hashtable();
	private Hashtable paramsBigDecimal = new Hashtable();
	private Hashtable paramsFree       = new Hashtable();
	private String lastSql_ = null;

	private String getString(String name){
		if(name==null) return "";
		String returnStr = (String)paramsString.get(name);
		if(returnStr==null) return "";
		return "'"+FrameworkCommon.stringReplaceSQuote(returnStr)+"'";
	}

	private String getBigDecimal(String name){
		if(name==null) return "";
		BigDecimal returnStr = (BigDecimal)paramsBigDecimal.get(name);
		if(returnStr==null) return "";
		return returnStr.toString();
	}

	private String getFree(String name){
		if(name==null) return "";
		String returnStr = (String)paramsFree.get(name);
		if(returnStr==null) return "";
		return returnStr;
	}

	public String getLastSql(){
		return lastSql_;
	}

	public SelectResultRset SELECT_SCMMD(FrameworkDbCommon db) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append("	SELECT");
		sql.append("	TRIM(NVL(SLCP_CD     ,'')) AS SLCP_CD     ,");
		sql.append("	TRIM(NVL(PTNR_CD     ,'')) AS PTNR_CD     ,");
		sql.append("	TRIM(NVL(ITM_NO      ,'')) AS ITM_NO      ,");
		sql.append("	TRIM(NVL(TRSP_STYL_CD,'')) AS TRSP_STYL_CD,");
		sql.append("	TRIM(NVL(GNR_ADM_NO,'')) AS GNR_ADM_NO,");
		sql.append("	TRIM(NVL(P_E_A_BGN_DT,'')) AS P_E_A_BGN_DT,");
		sql.append("	TRIM(NVL(P_E_A_END_DT,'')) AS P_E_A_END_DT,");
		sql.append("	TRIM(NVL(LOCK_LT     ,'')) AS LOCK_LT     ,");
		sql.append("	TRIM(NVL(INDC_ODR_LT ,'')) AS INDC_ODR_LT ,");
		sql.append("	TRIM(NVL(INDC_ODR_LT2,'')) AS INDC_ODR_LT2,");
		sql.append("	TRIM(NVL(RPL_DVSN_CD ,'')) AS RPL_DVSN_CD ,");
		sql.append("	TRIM(NVL(ODR_DVSN_CD ,'')) AS ODR_DVSN_CD ,");
		sql.append("	TRIM(NVL(RGS_PGM_NM  ,'')) AS RGS_PGM_NM  ,");
		sql.append("	TRIM(NVL(RGS_USR_ID  ,'')) AS RGS_USR_ID  ,");
		sql.append("	TO_CHAR(NVL(RGS_DTTM,''),'YYYYMMDDHH24MISS') AS RGS_DTTM,");
		sql.append("	TRIM(NVL(CHG_PGM_NM  ,'')) AS CHG_PGM_NM  ,");
		sql.append("	TRIM(NVL(CHG_USR_ID  ,'')) AS CHG_USR_ID  ,");
		sql.append("	TO_CHAR(NVL(CHG_DTTM,''),'YYYYMMDDHH24MISS') AS CHG_DTTM,");
		sql.append("	TRIM(NVL(CHG_TMS     ,'')) AS CHG_TMS,");
		sql.append("	TRIM(NVL(DEL_TYP     ,'')) AS DEL_TYP");
		sql.append("	FROM SCMMD ");
		sql.append("	WHERE ");
		sql.append("	SLCP_CD "+((getString("SLCP_CD").equals(""))?" is null ":"=")+getString("SLCP_CD")+"  ");
		sql.append("	AND PTNR_CD "+((getString("PTNR_CD").equals(""))?" is null ":"=")+getString("PTNR_CD")+" ");
		sql.append("	AND ITM_NO "+((getString("ITM_NO").equals(""))?" is null ":"=")+getString("ITM_NO")+"");
		sql.append("	AND TRSP_STYL_CD "+((getString("TRSP_STYL_CD").equals(""))?" is null ":"=")+getString("TRSP_STYL_CD")+"");
		sql.append("	AND GNR_ADM_NO "+((getString("GNR_ADM_NO").equals(""))?" is null ":"=")+getString("GNR_ADM_NO")+"");
		db.setSql(sql.toString());
		lastSql_ =sql.toString();
		SelectResultRset srr = db.executeQuery();
		paramsString     = new Hashtable();
		paramsBigDecimal = new Hashtable();
		paramsFree       = new Hashtable();

		return srr;
	}


	public void setSLCP_CD(String value){
		if(value==null) {
			paramsString.remove("SLCP_CD");
			return;
		}
		paramsString.put("SLCP_CD",value);
	}


	public void setPTNR_CD(String value){
		if(value==null) {
			paramsString.remove("PTNR_CD");
			return;
		}
		paramsString.put("PTNR_CD",value);
	}


	public void setITM_NO(String value){
		if(value==null) {
			paramsString.remove("ITM_NO");
			return;
		}
		paramsString.put("ITM_NO",value);
	}


	public void setTRSP_STYL_CD(String value){
		if(value==null) {
			paramsString.remove("TRSP_STYL_CD");
			return;
		}
		paramsString.put("TRSP_STYL_CD",value);
	}


	public void setGNR_ADM_NO(String value){
		if(value==null) {
			paramsString.remove("GNR_ADM_NO");
			return;
		}
		paramsString.put("GNR_ADM_NO",value);
	}


}
